package com.click.app.dao.hibernate;

import com.click.app.dao.PackageDetailDao;
import com.click.app.model.PackageDetail;
import java.util.List;

/**
 * @author Joel Chuca Condo
 * @date 04/05/2009
 */
public class PackageDetailDaoHibernate extends GenericDaoHibernate<PackageDetail, Long> implements PackageDetailDao {

    public PackageDetailDaoHibernate(){
        super(PackageDetail.class);
    }

    public List<PackageDetail> packagesAvailable() {
        return getHibernateTemplate().find("from PackageDetail where stock>0");
    }
    public List<PackageDetail> getByPackageName(String packageName){
        return getHibernateTemplate().find("from PackageDetail where stock>0 AND packageName=?" , packageName);
    }
    public Long getLastId() {
        List<PackageDetail> pd = getHibernateTemplate().find("from PackageDetail order by id desc");
        if (pd.isEmpty()) {
            return (new Long(0));
        } else {
            return pd.get(0).getId();
        }
    }
    public List<String> getUniqueName(){
         return getHibernateTemplate().find("select distinct pckDet.packageName from PackageDetail pckDet ");
    }
    public List<PackageDetail> getByPackageNameAndRealQuantNoCero(String packageName){
        return getHibernateTemplate().find("from PackageDetail where stock>0 AND packageName=? AND realQuantity>0" , packageName);
    }
}
